﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace CodeCamp.Infrastructure
{
    public static class MembershipHelper
    {

        public static bool ResetPassword(string email)
        {

            var username = Membership.GetUserNameByEmail(email);

            if (string.IsNullOrEmpty(username)) return false;

            var user = Membership.GetUser(username);

            if (user == null) return false;

            var password = user.ResetPassword();

            SendPasswordResetMail(user.Email, password);
            
            return true;

        }

        public static void SendPasswordResetMail(string recipient, string newPassword)
        {
            MailHelper.SendMail(recipient, "Your password has been reset", "<p>Please find your new password below:</p><p>" + newPassword + "</p><p><a href='www.portlandcodecamp.org'>Portland Code Camp</a></p>");
        }

    }
}